<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include(INCLUDE_USERSESSION);

class MY_Controller extends CI_Controller
{
   
    public $session;
    private $_controller_access;
    public function __construct()
    {
        define('PER_PAGE_CRM', 25);
        parent::__construct();
        $this->session = usersession::getInstance(); //Сессия
        
        $this->_controller_access = array(
            'Authorization'=>2 ,
            'Client'=> 2,
            'Orders'=> 2,
            'Selling'=> 2,
            'SomeClient'=> 2,
            'SomeOrder'=> 2,
            'SomeProduct'=> 2,
            'Storage'=> 2,
            'Settings'=> 1
        );
        //$this->getIp();
    }
    
    protected function issetSession($controller)
    {
        $s = $this->session->getSession();

        if( empty($s['userdata']))
        {
            redirect(site_url("authorization/"), 'refresh');
        }
        else
        {
           $this->crud->assign('access',$s['userdata'][2])->assign('person' ,$s['userdata'][3].' '.$s['userdata'][4].' '.$s['userdata'][5]);
           $this->access($controller);
        }
    }
    
    protected function access($controller)
    {
        $s = $this->session->getSession();
        foreach($this->_controller_access as $key=>$value)
        {
            if($key  == $controller && (int)$s['userdata'][2] > $value )
            {
                redirect("/index.html");
            }
        }
    }
}